package jdclib.io;


/**
 * 
 * The parseable interface outlines methods that can be used to parse and generate text based representations of the 
 * implementing class. 
 * 
 * @author Davis Clark
 */
public interface Parseable<TParse> 
{	
	/**
	 * This method should simply wrap a constructor "TParse(byte[] data)", and return the NEW INSTANCE of TParse.
	 * The static method <code>HybridReader.readAllParseable(..)</code> depends on the output of 
	 * this method being a NEW instance of TParse. If this method simply assigns a new value to global variables from 'data',
	 * and returns the same instance of TParse, <code>HybridInputStream.readAllParseable(...)</code> will return a
	 * LinkedList with the correct number of elements, but each element will be an identical copy of the last element. 
	 * 
	 * @param data The byte[] representation of an instance of TParse.
	 * @return The NEW INSTANCE, not a pointer or copy, of TParse.
	 */
	public TParse parse(byte[] data);
	
	/**
	 * Used to obtain the byte[] representing the delimiting sequence for an instance of TParse. Unless this sequence is being generated
	 * dynamically based on global variable values, it is recommended that this method simple return the value of a 
	 * 'static final' class variable.
	 * @return 	byte[]	
	 */
	public byte[] getDelimiterValue();
	
	/**
	 * Determines if newlines should be completely ignored in reading instances of TParse.
	 * **IMPORTANT!: If  the output of 'HybridReader.getDelimiterValue' contains a byte(s) with an integer representation of 10 or 13,
	 * this method MUST return false. 
	 * @return true || false
	 */
	public boolean skipNewLines();
	
	/**
	 * Determines if the delimiter value should be included in the byte[] parameter of the parse(byte[]) method
	 * @return boolean
	 */
	public boolean returnDelimiter();
	
	
	
	/*
	 * Following is an example of a CORRECT implementation of Parseable<TParse>:
	 * 
	 * 
			public class Person implements Parseable<Person>
			{
				public String Name;
				public int Age;
				
				public static final String INSTANCE_DELIMITER_STRING = "|";
				public static final byte[] DELIMITER_BYTE_ARRAY = Person.INSTANCE_DELIMITER_STRING.getBytes();
				public static final boolean SKIP_NEW_LINES = true;
				public static final String PROPERTY_DELIMITER = " ";
				
				public Person()
				{
					
				}
				
				public Person(byte[] data)
				{	
					String[] args = new String(data).split(Person.PROPERTY_DELIMITER);
					this.Name = args[0];
					this.Age = Integer.parseInt(args[1]);
				}
				
				public Person(String name, int age)
				{
					Name = name;
					Age = age;
				}
				
				@Override
				public String toString()
				{
					return String.format("Name: %s , Age: %d", Name, Age);
				}
			
				@Override
				public byte[] getDelimiterValue()
				{
					return Person.DELIMITER_BYTE_ARRAY;
				}
			
				@Override
				public Person parse(byte[] data)
				{
					return new Person(data);
				}
			
				@Override
				public boolean skipNewLines()
				{
					return Person.SKIP_NEW_LINES;
				}
			}
	 */



}
